package com.restaurant.springboot.utils;

import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;

/**
 * @Author jack
 * @Date:2019/8/1 16:47
 */
public class EhcacheUtil {
    /**
     * 设置缓存对象
     * @param cacheManager
     * @param key
     * @param object
     */
    public static void setCache(CacheManager cacheManager, String key, Object object){
        Cache cache = cacheManager.getCache("objectCache");
        cache.put(key, object);
    }

    /**
     * 从缓存中取出对象
     * @param cacheManager
     * @param key
     * @return
     */
    public static Object getCache(CacheManager cacheManager,String key){
        Object object = null;
        Cache cache = cacheManager.getCache("objectCache");
        if(cache.get(key) == null){
            return null;
        }else{
            return cache.get(key).get();
        }
    }
}
